#!/bin/bash

# 获取临时密码
temp_password=$(gawk '/root@localhost: /{print $13}' /data/mysql/mysqld.log)

# 下面命令说明: (1)使用临时密码登录。(2)修改root密码。()并设置允许远程访问
echo 'alter user "root"@"localhost" identified by "{{ mysql_root_password }}"; \
      create user "root"@"%" identified BY "{{ mysql_root_password }}"; \
      grant all on *.* to "root"@"%"; \
      flush privileges;  \
    ' | mysql -uroot -p"$temp_password" --connect-expired-password

